//
//  ProgressManagerViewController.swift
//  TXiOSDemoApp
//
//  Created by xicheng on 16/11/26.
//  Copyright © 2016年 xicheng. All rights reserved.
//

import UIKit

class ProgressManagerViewController: TXBaseViewController {

  private var toMainBtn:UIButton! = nil
  
  private var toErrorBtn:UIButton! = nil

  private var toEmptyBtn:UIButton! = nil
  
  override func initView() {
    
    self.naviBar.title = "ProgressManagerViewController"
    
    toErrorBtn = UIButton()
    toErrorBtn.setTitleColor(UIColor.black, for: .normal)
    toErrorBtn.setTitle("点击展示Error视图", for: .normal)
    toErrorBtn.backgroundColor = UIColor.green
    toErrorBtn.sizeToFit()
    toErrorBtn.center = CGPoint(x: kMainScreenWidth / 2, y: kMainScreenHeight / 2 - 50)
    self.view.addSubview(toErrorBtn)
    
    toEmptyBtn = UIButton()
    toEmptyBtn.setTitleColor(UIColor.black, for: .normal)
    toEmptyBtn.setTitle("点击展示空视图", for: .normal)
    toEmptyBtn.backgroundColor = UIColor.green
    toEmptyBtn.sizeToFit()
    toEmptyBtn.center = CGPoint(x: kMainScreenWidth / 2, y: kMainScreenHeight / 2 + 50)
    self.view.addSubview(toEmptyBtn)
  }
  
  override func initListener() {
    toErrorBtn.fixSingleClickListener(0.6, ClickListener.init(block: {
      [unowned self] in
      self.toError()
      }))
    
    toEmptyBtn.fixSingleClickListener(0.6, ClickListener.init(block: {
      [unowned self] in
      self.toEmpty("这是空试图")
      }))
  }
  
  override func initData() {
    Timer.schedule(delay: 2) { [weak self](handler) in
      guard let instance = self else{
        return
      }
      instance.toMain()
    }
  }
  
}

extension ProgressManagerViewController {
  
  override func errorViewClick() {
    self.toProgress()
    Timer.schedule(delay: 2.5) { [weak self](handler) in
      guard let instance = self else {
        return
      }
      instance.toMain()
    }
  }

}
